package com.cjbdi.service;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cjbdi.dao.FypzRepository;
import com.cjbdi.entity.Fypz;

/**
 * TFypz Service
 */
@Service
@Transactional
public class TFypzService{
    public List getFymc(String fybm){  
		List list = entityManager  
                .createNativeQuery("select c_mc from t_fypz where c_fbdm='"+fybm+"'")  
                .getResultList();  
        return list;
    }

    public List getParentFymc(String fybm,String fyLevel){  
    	String sql = "";
    	if(fyLevel.equals("gaoji")) {
    		sql = "select c_mc,c_fbdm from t_fypz where c_fbdm=(select substring(c_fbdm from 1 for 1)||'00' from t_fypz where c_fbdm='"+fybm+"' and c_mc not like'%已撤销%')";
    	}else {
    		sql = "select c_mc,c_fbdm from t_fypz where c_fbdm=(select substring(c_fbdm from 1 for 2)||'0' from t_fypz where c_fbdm='"+fybm+"' and c_mc not like'%已撤销%')";
    	}
		List list = entityManager  
                .createNativeQuery(sql)  
                .getResultList();  
        return list;
    }
    
    public List getFyjc(String fybm){  
		List list = entityManager  
                .createNativeQuery("select fyjc from sfzs_czrk where fybm='"+fybm+"'")  
                .getResultList();  
        return list;
    }
    @Autowired  
    @PersistenceContext  
    private EntityManager entityManager;// 注入EntityManager实例
    
    @Autowired 
    FypzRepository tFypzRepository;
    public List<Fypz> queryAll(){  
    	return tFypzRepository.queryAll();
    }
}
